<template>
    <div class="edu-page-warp">
        <ConditionCard
            shadow="never"
            body-style="padding: 24px 24px 6px 24px;"
            @search="onSubmit"
            @reset="reset('queryForm')"
        >
            <el-form ref="queryForm" :model="queryForm" label-position="right" label-width="135px">
                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="8">
                        <el-form-item :label="$t('graduationList.originalGraduationYear') + ':'" prop="graduationDate">
                            <el-date-picker
                                v-model="queryForm.graduationDate"
                                type="year"
                                style="width:100%"
                                value-format="yyyy"
                                clearable
                                @change="graduationDateChange" 
                                :placeholder="$t('graduationList.pleaseSelect')">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.college') + ':'" prop="faculty" >
                            <el-select
                                v-model="queryForm.faculty"
                                style="width: 100%;"
                                :filterable='role != 3' 
                                :clearable='role !=3'
                                @change="getMajorOptions"
                            >
                                <el-option
                                    v-for="item in options.faculty"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="8">
                        <el-form-item :label="$t('graduationList.auditBatch') + ':'" prop="reviewBatch">
                            <el-select v-model="queryForm.reviewBatch" filterable clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.reviewBatch"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.college') + ':'" prop="faculty" >
                            <el-select
                                v-model="queryForm.faculty"
                                style="width: 100%;"
                                :filterable='role != 3' 
                                :clearable='role !=3'
                                @change="getMajorOptions"
                            >
                                <el-option
                                    v-for="item in options.faculty"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item filterable :label="$t('label.major') + ':'" prop="profession">
                            <el-select v-model="queryForm.profession" @change="changeProfession" filterable clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.profession"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('auditStandard.proDirection') + ':'" prop="directionCode">
                            <el-select v-model="queryForm.directionCode" style="width: 100%" filterable clearable>
                              <el-option v-for="item in options.direction" :key="item.key" :label="item.label" :value="item.value">
                              </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item filterable :label="$t('graduationList.originalCollegeAuditConclusion') + ':'" prop="orginManualConclusion">
                            <el-select v-model="queryForm.orginManualConclusion" clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.collegeAuditConclusion"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item filterable :label="$t('graduationList.collegeAuditConclusion') + ':'" prop="collegeAuditConclusion">
                            <el-select v-model="queryForm.collegeAuditConclusion" clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.collegeAuditConclusion"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('culturePlan.degreeType') + ':'" prop="degreeType">
                            <el-select v-model="queryForm.degreeType" clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.degreeType"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item filterable :label="$t('graduationList.machineReviewConclusion') + ':'" prop="machineConclusion">
                            <el-select v-model="queryForm.machineConclusion" clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.machineConclusion"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item filterable :label="$t('graduationList.auditResults') + ':'" prop="isConclusionConformity">
                            <el-select v-model="queryForm.isConclusionConformity" clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.isConclusionConformity"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item filterable :label="$t('graduationList.submissionStatus') + ':'" prop="submit">
                            <el-select v-model="queryForm.submit" clearable style="width: 100%">
                                <el-option
                                    v-for="item in options.submit"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>                    -->
                </el-row>
            </el-form>
        </ConditionCard>
        <el-card shadow="never" body-style="padding: 24px;" class="card-margin">
            <h1 class="condition-title ">
                <span v-show='queryForm.graduationDate'>{{queryForm.graduationDate}}年</span>{{ $t('graduationList.completeGraduationReviewList') }}
                <template v-if="roleShow">
                    <span  class="title-tips">|</span>
                    <span  class="title-tips" v-if="listBatch" style="color: #ff5151;">当前审核批次：{{listBatch}}</span>
                    <span  class="title-tips" style="color: #ff5151;" v-else>尚未开启审核</span>
                </template>
                </h1>
            <div class="div-main clearfix">   
                <div class="float-left">
                    <el-input
                        v-model="queryForm.name"
                        :placeholder="$t('graduationList.please')"
                        prefix-icon="el-icon-search"
                        @change="handleSearch"
                    />
                </div>
                <div class="float-right">
                    <!-- <el-button  @click="btnSet">
                        {{ $t('graduationList.setMachineReview') }}
                    </el-button> -->
                    <el-button type="primary"  @click="btnPass">
                        {{ $t('graduationList.btn12') }}
                    </el-button>
                </div>
            </div>
            <EduTable
                :data="tableData"
                @page-change="handleCurrentChange"
                @selection-change="handleSelectionChange"
                :total="queryForm.total"
                :pageSize="queryForm.pageSize_"
                :page-num="queryForm.pageNum_"
                :orderFixed="fixed"
                :selectFixed="fixed"
                :cellClassName="preline"
            >
                <el-table-column :label="$t('graduationList.studentID')" prop="studentId" fixed="left"></el-table-column>
                <el-table-column :label="$t('graduationList.name')" prop="name" fixed="left"></el-table-column>
                <el-table-column :label="$t('label.college')" prop="facultyI18n" width="130"></el-table-column>
                <el-table-column :label="$t('label.major')" prop="professionI18n" width="160"></el-table-column>
                <el-table-column :label="$t('graduationList.machineReviewConclusion')" prop="machineConclusionI18n"></el-table-column>
                <el-table-column :label="$t('graduationList.collegeAuditConclusion')" width="110">
                    <template slot-scope="scope">
                        <span v-if="scope.row.collegeAuditConclusion == 4">{{$t('graduationList.permanentClosure')}}</span>
                        <span v-else>{{scope.row.collegeAuditConclusionI18n}}</span>
                     </template>
                </el-table-column>
                <el-table-column :label="$t('graduationList.originalCollegeAuditConclusion')" prop="orginManualConclusionI18n" width="140"></el-table-column>
                <el-table-column :label="$t('graduationList.isEffective')">
                    <template slot-scope="scope">
                        <span v-if="scope.row.isValidity == 1"  size="mini">{{ $t("graduationList.yes") }}</span>
                        <span v-if="scope.row.isValidity == 0"  size="mini">{{ $t("graduationList.no") }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="$t('graduationList.gradePoint')" prop="scorePoint"></el-table-column>
                <el-table-column :label="$t('graduationList.auditResults')" prop="isConclusionConformity" width="140">
                    <template slot-scope="scope">
                        <span v-if="scope.row.isConclusionConformity == 1" type="success" size="mini">{{ $t("graduationList.consistent") }}</span>
                        <span v-if="scope.row.isConclusionConformity == 2" type="warning" size="mini">{{ $t("graduationList.inconsistent") }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="$t('graduationList.machineReviewNotes')" width="300">
                    <template slot-scope="scope">
                        <div v-html="scope.row.machineRemark"></div>
                    </template>
                </el-table-column>
                <el-table-column :label="$t('graduationList.details')" width="370">
                    <template slot-scope="scope">
                        <div v-html="scope.row.machineDetails"></div>
                    </template>
                </el-table-column>
                <el-table-column :label="$t('graduationList.failingCourse')" prop="noPassCourse" width="240"></el-table-column>
                <el-table-column :label="$t('graduationList.machineReviewTime')" prop="machineDate" width="155"></el-table-column>
                <!-- <el-table-column :label="$t('graduationList.auditBatch')" >
                    <template slot-scope="scope">
                        <span v-if="scope.row.reviewBatchI18n"  size="mini">{{ scope.row.reviewBatchI18n }}</span>
                        <span v-else  size="mini">{{ $t("graduationList.noPending") }}</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="审核批次1" width="120" prop="reviewBatch1"></el-table-column>
                <el-table-column label="审核批次2" width="120" prop="reviewBatch2"></el-table-column>
                <el-table-column :label="$t('graduationList.remark')" prop="manualRemark" width="165"></el-table-column>
                <el-table-column :label="$t('graduationList.submissionStatus')" fixed="right">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.submit == 1" type="success" size="mini">{{ $t("graduationList.submitted") }}</el-tag>
                        <el-tag v-if="scope.row.submit == 2" type="warning" size="mini">{{ $t("graduationList.returned") }}</el-tag>
                        <!-- <el-tag v-if="scope.row.submit == 3" type="info" size="mini">{{ $t("graduationList.submitted") }}</el-tag> -->
                        <el-tag v-if="scope.row.submit == 0 || scope.row.submit == 3" type="danger" size="mini">{{ $t("graduationList.unsubmitted") }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column :label="$t('graduationList.operating')" width="80" fixed="right">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.isShowViewBtn" type="text" @click.stop="preview(scope.row,'VIEW')" size="mini">
                           {{ $t("graduationList.preview") }}
                        </el-button>
                        <el-button v-else :disabled="isDisabled" :class="{'review-danger': !isDisabled}" type="text" @click.stop="preview(scope.row,'AUDIT')" size="mini">
                           {{ $t("graduationList.review") }}
                        </el-button>
                    </template>
                </el-table-column>
            </EduTable>
        </el-card>
        <el-dialog
            title="设置机审"
            :visible.sync="showCourseDialog"
            width="40%"
            @close="resetFormValidate()"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <div class="title-dialog">
                 <span style="margin-right:8px">|</span>默认毕业设计(论文)通过
            </div>
            <el-form
                ref="mechineForm"
                :model="mechineForm"
                :rules="mechineRules"
                label-width="125px"
                label-position="right"
                size="mini"
                class="bg-white"
            >
                <el-row>
                    <el-col :span="18" :offset='1'>
                        <el-form-item :label="$t('graduationList.compeleteGraduationYear') + ':'" prop="graduationDate">
                            <el-date-picker
                                v-model="mechineForm.graduationDate"
                                type="year"
                                style="width:100%"
                                value-format="yyyy"
                                @change="getReviewBatch2" 
                                :placeholder="$t('graduationList.pleaseSelect')">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="18" :offset='1'>
                         <el-form-item :label="$t('graduationList.auditBatch') + ':'" prop="reviewBatch">
                            <el-select v-model="mechineForm.reviewBatch" style="width: 100%">
                                <el-option
                                    :key="6"
                                    label="全部"
                                    value="6"
                                />
                                <el-option
                                    v-for="item in mechineOptions.reviewBatch"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-row>
                <el-col :span="24">
                    <div class="float-right">
                        <el-button @click="cancelDialog">{{ $t('common.btn.cancel') }}</el-button>
                        <el-button
                            type="primary"
                            @click="confirmDialog"
                        >{{ $t('common.btn.confirm') }}</el-button>
                    </div>
                </el-col>
            </el-row>
        </el-dialog>
        <el-dialog
            :title="title"
            :visible.sync="showPrintDialog"
            width="40%"
            @close="resetPrintValidate()"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <el-form
                ref="printForm"
                :model="printForm"
                :rules="printRules"
                label-width="125px"
                label-position="right"
                size="mini"
                class="bg-white"
            >
                <el-row v-if="$t('graduationList.btn12') == title">
                    <el-col :span="19" :offset='1'>
                        <el-form-item label="打印类型:" prop="printType">
                            <el-select v-model="printForm.printType" @change="checkType" style="width: 100%">
                                <el-option
                                    v-for="item in mechineOptions.exportType"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="19" :offset='1'>
                        <el-form-item :label="$t('graduationList.compeleteGraduationYear') + ':'" prop="graduationDate">
                            <el-date-picker
                                v-model="printForm.graduationDate"
                                type="year"
                                style="width:100%"
                                value-format="yyyy"
                                @change="getReviewBatch2"
                                :placeholder="$t('graduationList.pleaseSelect')">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="19" :offset='1'>
                        <el-form-item :label="$t('graduationList.auditBatch') + ':'" prop="reviewBatch">
                            <el-select v-model="printForm.reviewBatch" style="width: 100%">
                                <el-option
                                    v-for="item in mechineOptions.reviewBatch"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-row>
                <el-col :span="24">
                    <div class="float-right">
                        <el-button @click="printCancelDialog">{{ $t('common.btn.cancel') }}</el-button>
                        <el-button
                            type="primary"
                            @click="printConfirmDialog"
                        >{{ $t('common.btn.confirm') }}</el-button>
                    </div>
                </el-col>
            </el-row>
        </el-dialog>
    </div>
</template>
<script>
import UTILS from "common/src/utils/utils";
import { queryDic, findTrainingLevelByProjId } from "common/src/api/dictionary";
// import { findFaculty } from "common/src/api/faculty";
import {findAllGraduateReviewBatch,findGraduateList,saveOrSubmitCollegeAudit,setMachine,selectCurrentBatch,getRedisResult, printPdfInList, findFaculty} from 'common/src/api/graduationManagement/suspendToGraduateList'
import { getPower } from "common/src/api/culture/culturePlan";
import {HIDE_FACULTYCODE} from '../components/gradMangeUtis'
import mixin from 'common/src/mixins/index';
export default {
    name: "graduationQualificationAudit",
    mixins: [mixin],
    data() {
        //let currentYear = new Date().getFullYear();
        return {
            // 筛选相关选项
            queryForm: {
                isOverseas: "0",
                grade: "", // 年级
                graduationDate: '', 
                reviewBatch: "", 
                faculty: "", 
                profession: "", 
                directionCode: '',
                machineConclusion:"",
                collegeAuditConclusion:"",
                orginManualConclusion:"",
                submit:"",
                isConclusionConformity: "", 
                degreeType:"",
                pageNum_: 1,
                pageSize_: 20,
                name:"",
                total: 0,
                isValidity:"1"
            },
            fixed:true,
            studentAuditTip: '',
            // 下拉相关选项数据
            options: {
                graduationDate:[],
                reviewBatch: [],
                trainingLevel: [],
                professionCateGory: [],
                faculty: [],
                profession: [],
                direction: [],
                collegeAuditConclusion: [],
                degreeType:[],
                machineConclusion:[],
                submit: [
                    {
                        value: "0",
                        label: this.$t("graduationList.unsubmitted")
                    },
                    {
                        value: "1",
                        label: this.$t("graduationList.submitted")
                    },
                    {
                        value: "2",
                        label: this.$t("graduationList.returned")
                    }
                ],
                isConclusionConformity: [
                    {
                        value: "1",
                        label: this.$t("graduationList.consistent")
                    },
                    {
                        value: "2",
                        label: this.$t("graduationList.inconsistent")
                    }
                ]
            },
            mechineRules: {
                graduationDate: [
                    {
                        required: true,
                        message: "请选择审核年份",
                        trigger: "change"
                    }
                ],
                reviewBatch: [
                    {
                        required: true,
                        message: "请选择审核批次",
                        trigger: "change"
                    }
                ],
            },
            mechineForm: {
                isOverseas: "0",
                graduationDate: "", 
                reviewBatch: "", 
            },
            mechineOptions: {
                reviewBatch: [],
            },
            tableData: [],
            ids: [],
            role:'',
            roleShow:false,
            studentNo:'',
            resultNo:'',
            preline:'preline',
            showCourseDialog:false,
            listBatch:'',
            loading:false,
            isDisabled:false,
            showPrintDialog:false,
            rawData:[],
            currentBatch:{
                reviewBatch:'',
                reviewBatchId:'',
                grade:'',
                id:''
            },
            printRules: {
                printType: [
                    {
                        required: true,
                        message: "请选择打印类型",
                        trigger: "change"
                    }
                ],
                graduationDate: [
                    {
                        required: true,
                        message: "请选择审核年份",
                        trigger: "change"
                    }
                ],
                reviewBatch: [
                    {
                        required: true,
                        message: "请选择审核批次",
                        trigger: "change"
                    }
                ]
            },
            printForm: {
                isOverseas: "0",
                printType:"",
                graduationDate: "", 
                reviewBatch: ""
            },
             mechineOptions: {
                reviewBatch: [],
                profession: [],
                exportTypeCopy:[],
                exportType:[
                    {
                        value: "3",
                        label: "补发证书审批单"
                    },
                    {
                        value: "4",
                        label: "发放签收单"
                    },
                ],
            },
        };
    },

    created() {
        this.getRole();
    },
    beforeRouteEnter (to, from, next) {
        next(vm=>{
            if (vm.queryForm.faculty) {
                vm.roleShow = !!vm.queryForm.graduationDate;
                vm.getListBatch();
            }else {
                vm.roleShow = false;
            }
            vm.handleSearch();
        })
    },
    methods: {
        init() {
            this.initOptions();
        },
        initOptions() {
            this.getFacultyList('init')
            // findFaculty().then(res => { 
            //     let data = {"X_YX": res.data};
            //     UTILS.fillSelect({ faculty: "X_YX" }, data, this.options);
            //     this.options.faculty = this.options.faculty.filter(item => {
            //         return (HIDE_FACULTYCODE || []).indexOf(item.value) === -1;
            //     })
            //     if (this.options.faculty.length == 1) {
            //         this.queryForm.faculty = this.options.faculty[0].value;
            //     }else {
            //         this.queryForm.faculty = '';
            //     }
            //     if (this.queryForm.faculty) {
            //         this.handleSearch();
            //         this.getListBatch();
            //     }
            // });
            // const data = {
            //     lang: this.$store.getters.language || "cn",
            //     type: "allChild",
            //     keys: ["G_XBIE", "X_PYLB", "G_MZ", "X_XWLX", "X_BYJL"]
            // };
            // queryDic(data).then(res => {
            //     if (res.code == 200) {
            //         UTILS.fillSelect(
            //             {
                            
            //                 degreeType: "X_XWLX",
            //                 collegeAuditConclusion: "X_BYJL",
            //                 machineConclusion: "X_BYJL"
            //             },
            //             res.data,
            //             this.options
            //         );
            //         this.options.collegeAuditConclusion = this.options.collegeAuditConclusion.filter(label => label.label != '肄业')
            //         this.options.machineConclusion = this.options.machineConclusion.filter(label => label.label != '肄业')
            //     }
            // });
        },
        getFacultyList(type) {
            let param = {
                graduationDate: this.queryForm.graduationDate || '',
                reviewDate: '',
                isOverseas: this.queryForm.isOverseas
            };
            this.queryForm.faculty = '';
            this.getFaculty(this.options, param, type);
        },
        getFaculty(options, param, type) {
            options = options || {};
            options.faculty = [];
            findFaculty(param).then(res => {
                let data = {
                    "X_YX": res.data
                };
                UTILS.fillSelect({
                    faculty: "X_YX"
                }, data, options);
                    options.faculty = options.faculty.filter(item => {
                        return (HIDE_FACULTYCODE || []).indexOf(item.value) === -1;
                    })
                    if (type == "init") {
                        if (this.options.faculty.length == 1) {
                            this.queryForm.faculty = this.options.faculty[0].value;
                        }else {
                            this.queryForm.faculty = '';
                        }
                        if (this.queryForm.faculty) {
                            this.handleSearch();
                            this.getListBatch();
                        }
                    }
                });
        },
        changeProfession() {
            //this.initDirection();
        },
        getListBatch(){
            if (!this.queryForm.graduationDate) {
                return;
            }
            selectCurrentBatch({
                isOverseas: '0',
                college: this.queryForm.faculty,
                grade: this.queryForm.graduationDate
            })
            .then(res => {
                if (res.code == 200) {
                    if(res.data.length > 0){
                        this.listBatch = res.data[0].reviewBatchI18n
                        this.isDisabled = false
                        for(let key in this.currentBatch){
                            this.currentBatch[key] = res.data[0]?res.data[0][key]:""
                        }

                    }else{
                        this.isDisabled = true;
                        this.listBatch = "";
                    }
                }
            });
        },
        graduationDateChange() {
            // this.getMajorOptions();
            // this.queryForm.reviewBatch = "";
            // this.getReviewBatch();
            this.getFacultyList();
            this.onSubmit(true);
        },
        getReviewBatch(){
            this.options.reviewBatch = [];
            if (!this.queryForm.graduationDate) {
                return;
            }
            let batchs = [];
            findAllGraduateReviewBatch({
                isOverseas: '0',
                graduateData: this.queryForm.graduationDate
            })
            .then(res => {
                if (res.code == 200) {
                    batchs = res.data.list.map((item, index) => {
                        return {
                            label: item.reviewBatchI18n,
                            value: item.reviewBatch
                        }
                    })
                }
            }).finally(res =>{
                this.options.reviewBatch = [{
                    label: '全部',
                    value:  ''
                },
                {
                    label: '未审核',
                    value:  '0'
                },
                ...batchs]
            });
        },
        getReviewBatch2(){
            this.mechineOptions.reviewBatch = [];
            this.mechineForm.reviewBatch = "";
            this.printForm.reviewBatch = '';
            findAllGraduateReviewBatch({
                isOverseas: '0',
                graduateData: this.printForm.graduationDate
            })
            .then(res => {
                if (res.code == 200) {
                    this.mechineOptions.reviewBatch = res.data.list.map((item, index) => {
                        return {
                            label: item.reviewBatchI18n,
                            value: item.reviewBatch
                        }
                    })
                    this.mechineOptions.reviewBatch.push({
                        value: "0",
                        label: "未审核"
                    },
                    {
                        value: "6",
                        label: "全部"
                    },)
                    this.printForm.reviewBatch = '6'
                }
            }); 
        },
        getRole() {
            getPower().then(res => {
                this.role = res.data.power
                if(this.role == 4){
                    this.handleSearch();
                }
                this.init();
            });
        },
        handleSearch() {
            if (!this.queryForm.graduationDate) {
                this.tableData = [];
                this.rawData = [];
                this.queryForm.pageNum_ = 1;
                this.queryForm.total = 0;
                this.studentNo = 0;
                this.resultNo = 0;
                this.studentAuditTip = '';
                return;
            }
           
            let param = {
                graduationDate: this.queryForm.graduationDate,
                faculty: this.queryForm.faculty,
                isOverseas: this.queryForm.isOverseas,
                isValidity: this.queryForm.isValidity,
                name: this.queryForm.name,
                pageNum_: this.queryForm.pageNum_,
                pageSize_: this.queryForm.pageSize_,
                isReview: '1'
            }
            findGraduateList(param).then(res => {
                if (res.code == 200) {
                    this.tableData = res.data.list;
                    this.rawData = _.cloneDeep(res.data.list)
                    this.formatTableData(this.tableData);
                    this.queryForm.pageNum_ = res.data.pageNum_;
                    this.queryForm.pageSize_ = res.data.pageSize_;
                    this.queryForm.total = res.data.total_;
                    this.studentNo = res.data.total_
                    let resultNo = res.data.list.filter(tempItem => tempItem.isConclusionConformity == 2)
                    this.resultNo = res.msg || 0;
                }
            });
        },
        formatTableData(data) {
            data = data || [];
            let reg1 = /(;)?<br>$/g;
            let reg2 = /(;)?<br>;/g;
            data.forEach(item => {
                item.professionI18n = item.professionName || item.professionI18n;
                if (item.directionName) {
                    item.professionI18n &&  (item.professionI18n =  item.professionI18n + ` [${item.directionName}]`);
                }
                item.machineDetails = item.machineDetails && item.machineDetails.replace(reg1, '') || '';
                item.machineDetails = item.machineDetails.replace(reg2, ';<br>');
                item.machineRemark = item.machineRemark && item.machineRemark.replace(reg1, '') || '';
                item.machineRemark = item.machineRemark.replace(reg2, ';<br>');
                item.isShowViewBtn = false;
                // 毕业且授予学位，不能再进行审核
                if (item.directedDegree == 1 && item.collegeAuditConclusion == 1) {
                    item.isShowViewBtn = true; 
                }
            })
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val.pageNum;
            this.queryForm.pageSize_ = val.pageSize;
            this.handleSearch();
        },
        selectionChange(selection) {
            const self = this;
            self.multipleSelection = selection;
        },
        getMajorOptions() {
            this.onSubmit(true);
            // this.options.profession = [];
            // this.queryForm.profession = "";
            // this.options.direction = [];
            // this.queryForm.directionCode = "";
            // this.professionMap = {};
            // if (!this.queryForm.graduationDate) {
            //    return;
            // }
            // manageApi.getProfessionByGrade({
            //     faculty: this.queryForm.faculty,
            //     graduateDate: this.queryForm.graduationDate,
            // })
            // .then(res => {
            //     if (res.code == 200) {
            //         let data = res.data || [];
            //         this.options.profession = data.map((item, index) => {
            //             this.professionMap[item.professionCateGory] = item.grade;
            //             return {
            //                 label: item.professionCateGoryName + '-' + item.professionCateGory,
            //                 value: item.professionCateGory
            //             }
            //         })
            //     }
            // });
        },

        onSubmit(noTip) {
            this.queryForm.pageNum_ = 1
            this.queryForm.pageSize_ = 20
            if (this.queryForm.faculty) {
                this.roleShow = !!this.queryForm.graduationDate;
                this.getListBatch();
            }else {
                this.roleShow = false;
            }
            if (!this.queryForm.graduationDate && !noTip) {
                this.$message({
                    type: "warning",
                    message: '请选择原毕业年份'
                });
            }
            this.handleSearch();
        },
        reset(ref) {
            this.options.direction = [];
            this.queryForm.name = "";
            this.queryForm.pageNum_ = 1;
            this.queryForm.pageSize_ = 20;
            this.$refs[ref].resetFields();
            this.roleShow = false;
            if (this.role == 3) {
                this.queryForm.faculty = this.options.faculty[0].value
            }
            this.handleSearch();
        },
        detailCultureScheme(id) {
            getCultureSchemeById(id).then(res => {
                if (res.code == 200) {
                }
            });
        },
        // 表格多选值
        handleSelectionChange(row) {
            this.ids = row

        },
        btnSet() {
            if(!this.queryForm.faculty){
                this.$message({
                    type: "warning",
                    message: "请先选择要设置机审的学院"
                });
                return; 
            }
            this.showCourseDialog = true;
        },
        exportFile(type) {
            // const ids = _.map(this.multipleSelection, "id");
            // if(ids.length==0){
            //     this.$message({
            //         type: "warning",
            //         message: "请勾选培养方案再导出数据"
            //     });
            //     return; 
            // }
            // const str = ids.join(",");
            // let data={
            //     ids:str,
            //     type :type,
            //     projId:this.queryForm.projId,
            //     status:this.queryForm.status
            // };
            // data['x-token']=this.queryForm['x-token'];
            // exportCultureSchemePdfOrWordZip(data);
        },
        preview(row,mode){
            if(mode == 'AUDIT'){
                if (!this.queryForm.faculty){
                    this.$message({
                        type: "warning",
                        message: "请先选择要提交审核结论的学院"
                    });
                    return;
                }
                if (this.currentBatch.grade && this.listBatch) {
                    let currentBatch = this.currentBatch.grade + '年'+ this.listBatch;
                    if (currentBatch == row.reviewBatch1 || currentBatch == row.reviewBatch2) {
                        this.$message({
                            type: "warning",
                            message: "当前批次已有审核结论,请先退回审核结论,再进行审核"
                        });
                        return;
                    }
                }
            }
            this.$router.push({
                path: '/cgraduationQualificationAuditDetail',
                query: {
                    mode,
                    studentId:row.studentId,
                    currentBatch:this.currentBatch,
                    queryForm:this.queryForm
                }
            })
        },
        resetFormValidate() {
            // 清除表单校验
            this.$refs.mechineForm.resetFields();
            this.mechineOptions.reviewBatch = []
        },
        cancelDialog() {
            this.resetFormValidate();
            this.showCourseDialog = false;
        },
        confirmDialog() {
            this.$refs.mechineForm.validate(valid => {
                if (!valid) {
                    return;
                }
                let data = {
                    "reviewBatch": this.mechineForm.reviewBatch,
                    "graduationDate":this.mechineForm.graduationDate,
                    "isOverseas": "0",
                    "faculty": this.queryForm.faculty,
                };
                let sleep = ms => {
                    return new Promise(resolve => setTimeout(resolve, ms));
                };
                let loaded = false;
                let key = "";
                //重复发送请求，直到自动关联完成
                let delayRequest = async () => {
                    if (loaded) {
                        await sleep(5000);
                    } else {
                        loaded = true;
                    }
                    getRedisResult(key).then(response => {
                        if (response.code == 200 && response.data.status) {
                            this.$message({
                                type: "success",
                                message: "设置成功"
                            });
                            this.showCourseDialog = false;
                            this.handleSearch()
                        }else {
                            const loading = this.$loading({
                                lock: true,
                                text: "Loading",
                                spinner: "el-icon-loading",
                                background: "rgba(255, 255, 255, .48)"
                            });
                            delayRequest();
                        }
                    })
                    .catch(ex => {
                        
                    });
                }
                setMachine(data).then(response => {
                    if (response.code === 200) {
                        key = response.data.key;
                        delayRequest();
                    }
                });
            })
        },
        btnPass(){
            if (!this.queryForm.faculty) {
                this.$message({
                    type: "warning",
                    message: "请选择要打印的学院"
                });
                return;
            }
            this.title = this.$t("graduationList.btn12")
            this.showPrintDialog = true;
        },
        resetPrintValidate() {
            // 清除表单校验
            this.$refs.printForm.resetFields();
            this.title = "";
            this.flag = false;
            this.mechineOptions.reviewBatch = []
        },
        printCancelDialog(){
            this.resetPrintValidate();
            this.showPrintDialog = false;
        },
        checkType(){ 
            // this.printForm.graduationDate = ''
            // this.printForm.reviewBatch = ''     
        },
        printConfirmDialog(){
            this.$refs.printForm.validate(valid => {
                if (!valid) {
                    return;
                }
                let queryForm =_.cloneDeep(this.printForm);
                let data = _.cloneDeep(this.printForm)
                let queryParam = '';
                if(queryForm.reviewBatch == 6){
                    queryForm.reviewBatch = ''
                }
                queryParam = `printType=${queryForm.printType}&graduationDate=${queryForm.graduationDate}&faculty=${this.queryForm.faculty}&reviewBatch=${queryForm.reviewBatch}&isOverseas=0`;
                this.beforePrint(queryForm, queryParam);
                this.printCancelDialog()
            });    
        },
        async beforePrint(param, queryParam) {
            if (param.printType == 3 || param.printType == 4) {
                let {data} = await printPdfInList(queryParam);
                let url = `/api/studentservice/assessApply/previewPersonTitle?objectKey=${data}`;
                window.open(url);
            }
        }
        
    }
};
</script>
<style lang="scss" scoped>
.div-main {
    margin-bottom: 16px;
  }
.title-tips{
    margin-left: 8px;
    color: rgba(76, 92, 112, 0.850980392156863);
    font-size: 14px;
    font-weight: 300
}
.table-position{
    margin-top: -33px;
    width: 390px;
    p{
        font-size: 14px;
        color: #2B3B4E;
    }
    p + p{
        margin-top: 3px;
        font-size: 12px;
        color: rgba(76, 92, 112, 0.850980392156863);
    }
}
.title-dialog{
    position: absolute; 
    left: 110px;
    top:28px;
    font-size: 14px;
    color: rgba(76, 92, 112, 0.850980392156863);
}
.review-danger{
    color: #F56C6C;
}
</style>

